import re
import pathlib
from typing import List, Pattern, Optional

# --- Configuration Variables ---
# These can be eventually loaded from a file, environment variables, or CLI args.

# Default root directory to analyze (can be overridden)
# Set to None initially, should be provided by the user via CLI perhaps.
DEFAULT_PROJECT_ROOT: Optional[pathlib.Path] = None

# Default list of patterns (regex) for paths to exclude from analysis.
# Useful for ignoring virtual environments, test directories, data files, etc.
DEFAULT_EXCLUDE_PATTERNS: List[Pattern[str]] = [
    re.compile(r".*/\.[^/]*$"),
    re.compile(r".*/__pycache__$"),
    re.compile(r".*/site-packages$"),
    re.compile(r".*/venv$"),
    re.compile(r".*/env$"),
    re.compile(r".*\.env$"),
    re.compile(r".*/tests?$",),
    re.compile(r".*/docs?$",),
    re.compile(r".*\.egg-info$"),
    re.compile(r"/build/")
]

# Default output file name for the generated knowledge graph JSON.
DEFAULT_OUTPUT_FILE: str = "code_knowledge.json"

# --- Configuration Loading (Example - can be enhanced later) ---

class AppConfig:
    """Holds the application configuration."""
    def __init__(
        self,
        project_root: pathlib.Path,
        exclude_patterns: List[Pattern[str]] = DEFAULT_EXCLUDE_PATTERNS,
        output_file: str = DEFAULT_OUTPUT_FILE,
    ):
        self.project_root: pathlib.Path = project_root.resolve() # Ensure absolute path
        self.exclude_patterns: List[Pattern[str]] = exclude_patterns
        self.output_file: pathlib.Path = pathlib.Path(output_file)

        if not self.project_root.is_dir():
            raise ValueError(f"Project root directory not found: {self.project_root}")

# Example of how configuration might be loaded or used (will be refined in main.py)
# def load_config(cli_args=None) -> AppConfig:
#     # In a real scenario, parse cli_args, read files, etc.
#     # For now, requires project_root to be passed explicitly.
#     if cli_args and cli_args.project_dir:
#          root = pathlib.Path(cli_args.project_dir)
#          # Potentially load excludes/output from args too
#          return AppConfig(project_root=root)
#     elif DEFAULT_PROJECT_ROOT:
#          return AppConfig(project_root=DEFAULT_PROJECT_ROOT)
#     else:
#          raise ValueError("Project root directory must be specified.")

print("Config module loaded (Phase 0 placeholder).")